package com.weishi.project.training.controller;

import java.util.Date;
import java.util.List;

import com.weishi.project.system.domain.SysUser;
import com.weishi.project.training.domain.AnnualPlan;
import com.weishi.project.training.domain.NaturalYear;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.TrainingWeek;
import com.weishi.project.training.service.ITrainingWeekService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * trainingWeekController
 */
@Api(value = "训练周",description = "训练周")
@RestController
@RequestMapping("/training/trainingWeek")
public class TrainingWeekController extends BaseController {

    @Autowired
    private ITrainingWeekService trainingWeekService;

    /**
     * 查询训练周列表
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingWeek trainingWeek) {
        startPage();
        List<TrainingWeek> list = trainingWeekService.selectTrainingWeekList(trainingWeek);
        return getDataTable(list);
    }

    /**
     * 导出训练周列表
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:export')")
    @Log(title = "trainingWeek", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TrainingWeek trainingWeek) {
        List<TrainingWeek> list = trainingWeekService.selectTrainingWeekList(trainingWeek);
        ExcelUtil<TrainingWeek> util = new ExcelUtil<TrainingWeek>(TrainingWeek.class);
        return util.exportExcel(list, "trainingWeek");
    }

    /**
     * 获取训练周详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(trainingWeekService.getTrainingWeekById(id));
    }

    /**
     * 新增训练周
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:add')")
    @Log(title = "trainingWeek", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingWeek trainingWeek) {
        trainingWeek.setCtime(new Date());
        trainingWeekService.save(trainingWeek);
        return AjaxResult.success();
    }

    /**
     * 修改训练周
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:edit')")
    @Log(title = "trainingWeek", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingWeek trainingWeek) {
        trainingWeekService.updateById(trainingWeek);
        return AjaxResult.success();
    }

    /**
     * 删除训练周
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:remove')")
    @Log(title = "trainingWeek", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        trainingWeekService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 查询周期名称集合
     */
    @PreAuthorize("@ss.hasPermi('training:trainingWeek:list')")
    @GetMapping("/getAnnualPlanList")
    public TableDataInfo getAnnualPlanList(AnnualPlan annualPlan) {
        startPage();
        List<AnnualPlan> list = trainingWeekService.getAnnualPlan();
        return getDataTable(list);
    }

    /**
     * 查询用户名称集合
     */
    @GetMapping("/getSysUerList")
    public TableDataInfo list(SysUser sysUser) {
        startPage();
        List<SysUser> list = trainingWeekService.getSysUerList();
        return getDataTable(list);
    }

}